<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="model.User"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>
<div id="menu">
	<a href="/hmg/UserServlet">Users</a>
	|&nbsp;<a href="/hmg/RoomServlet">Rooms</a>
</div>
<%
String err = null;
User u = null;
Boolean status = (Boolean)request.getAttribute("status");
if(status != null){
  //si existe status => viene de loginservlet
	if(status){
	  //si loginservlet termino con exito
	  u = (User)request.getAttribute("user");
	  request.getSession(true).setAttribute("loggeduser", u);
	} else {
	  err = (String)request.getAttribute("error");
	  if(err != null){
	    %> <h3 class="error"> <%= err %> </h3> <%
	  } else {
	    %> <h3 class="error">An error has occurred. Please try again.</h3> <%
	  }
	}
}

if(request.getSession()==null || request.getSession().getAttribute("loggeduser")==null){
%>
<h4>Log in to play!</h4>
<div id="logindiv">
<form id="loginform" method="POST" action="LoginServlet">
<table>
	<tr>
		<td>Name:</td>
		<td><input type="text" name="name" id="name"/></td>
	</tr>
	<tr>
		<td>Password:</td>
		<td><input type="password" name="pass" id="pass"/></td>
	</tr>
	<tr>
		<td></td>
		<td><input type="submit" name="loginbutton" id="loginbutton" value="Login"/></td>
	</tr>
</table>
</form>
</div>
<%
} else {
  %> <h3 class='success'>Welcome <%= ((User)request.getSession().getAttribute("loggeduser")).getName() %>(<a href="/hmg/LoginServlet">logout)</a></h3><%
}
%>
</body>
</html>